package com.edu.networkexperimentation.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.edu.networkexperimentation.mapper.PaperMapper;
import com.edu.networkexperimentation.mapper.ResultMapper;
import com.edu.networkexperimentation.model.domain.Effect;
import com.edu.networkexperimentation.model.domain.Paper;
import com.edu.networkexperimentation.model.domain.Result;
import com.edu.networkexperimentation.service.EffectService;
import com.edu.networkexperimentation.mapper.EffectMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
* @author 29764
* @description 针对表【effect】的数据库操作Service实现
* @createDate 2024-04-07 12:27:10
*/
@Service
public class EffectServiceImpl extends ServiceImpl<EffectMapper, Effect>
    implements EffectService{

    @Resource
    private ResultMapper resultMapper;

    @Resource
    private PaperMapper paperMapper;

    @Override
    public List<Effect> getEffectsByPaperID(Long id) {
        QueryWrapper<Effect> effectQueryWrapper = new QueryWrapper<>();
        effectQueryWrapper.lambda().eq(Effect::getPaperid, id);
        Effect effect = this.getOne(effectQueryWrapper);
        QueryWrapper<Result> resultQueryWrapper = new QueryWrapper<>();
        resultQueryWrapper.lambda().eq(Result::getEffectid, effect.getId());
        Result result = resultMapper.selectOne(resultQueryWrapper);
        resultQueryWrapper.clear();
        resultQueryWrapper.lambda().eq(Result::getProcedureid, result.getProcedureid());
        List<Result> resultList = resultMapper.selectList(resultQueryWrapper);
        List<Effect> effectList = new ArrayList<>();
        resultList.forEach(item->{
            effectQueryWrapper.clear();
            effectQueryWrapper.lambda().eq(Effect::getId, item.getEffectid());
            effectList.add(this.getOne(effectQueryWrapper));
        });
        return effectList;
    }
}




